package cn.stylefeng.guns.modular.team.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.team.entity.Team;
import cn.stylefeng.guns.modular.team.mapper.TeamMapper;
import cn.stylefeng.guns.modular.team.model.params.TeamParam;
import cn.stylefeng.guns.modular.team.model.result.TeamResult;
import  cn.stylefeng.guns.modular.team.service.TeamService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.mapper.UserMapper;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 班级 服务实现类
 * </p>
 *
 * @author CHENCHEN
 * @since 2022-07-19
 */
@Service
public class TeamServiceImpl extends ServiceImpl<TeamMapper, Team> implements TeamService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void add(TeamParam param){
        Team entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TeamParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TeamParam param){
        Team oldEntity = getOldEntity(param);
        Team newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TeamResult findBySpec(TeamParam param){
        return null;
    }

    @Override
    public List<TeamResult> findListBySpec(TeamParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TeamParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public Map<String, Object> showTeachers() {
        HashMap<String, Object> map = new HashMap<>();
        //查询所有班主任，部门ID  1549942171308769281
        map.put("banzhuren", userMapper.selectTeacher(1549942171308769281L));
        //查询所有专高讲师，部门ID  1549940144960733186
        map.put("zhuanyegaoji", userMapper.selectTeacher(1549940144960733186L));
        //查询所有实训讲师，部门ID  1549940305589993473
        map.put("shixun", userMapper.selectTeacher(1549940305589993473L));
        return map;
    }

    private Serializable getKey(TeamParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private Team getOldEntity(TeamParam param) {
        return this.getById(getKey(param));
    }

    private Team getEntity(TeamParam param) {
        Team entity = new Team();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
